#if !defined(ximera_scripting_lua_stringconverter_hpp)
#define ximera_scripting_lua_stringconverter_hpp

// -----------------------------------------------------------

#include <ximera/config.hpp>
#include <ximera/common/utils.hpp>
#include <ximera/scripting/lua/luaincludes.hpp>

namespace luabind { namespace converters 
{
    static yes_t is_user_defined(by_value<ximera::String>);
    static yes_t is_user_defined(by_const_reference<ximera::String>);

    inline void convert_cpp_to_lua(lua_State* L, const ximera::String& s)
    {
        lua_pushstring(L, ximera::string_util::wstr2str(s).c_str());
    }

    inline ximera::String convert_lua_to_cpp(
        lua_State* L, by_value<ximera::String>, int index)
    {
        return ximera::string_util::str2wstr(lua_tostring(L, index));
    }

    inline ximera::String convert_lua_to_cpp(
        lua_State* L, by_const_reference<ximera::String>, int index)
    {
        return ximera::string_util::str2wstr(lua_tostring(L, index));
    }

    inline int match_lua_to_cpp(
        lua_State* L, by_value<ximera::String>, int index)
    {
        if (lua_type(L, index) == LUA_TSTRING) return 0;
        else return -1;
    }

    inline int match_lua_to_cpp(
        lua_State* L, by_const_reference<ximera::String>, int index)
    {
        if (lua_type(L, index) == LUA_TSTRING) return 0;
        else return -1;
    }
}}

// -----------------------------------------------------------

#endif
